<?php

/**
 * This is the model class for table "service".
 *
 * The followings are the available columns in table 'service':
 * @property integer $id
 * @property string $title
 * @property string $description
 * @property integer $user_id
 * @property integer $category_id
 * @property integer $activ
 * @property string $date_add
 * @property string $date_expire
 * @property string $img1
 * @property string $img2
 * @property string $img3
 * @property string $img4
 * @property string $img5
 */
class Service extends CActiveRecord
{
    public $amount;
    public $title_en;
    public $title_de;
    public $description_en;
    public $description_de;
	/**
	 * Returns the static model of the specified AR class.
	 * @param string $className active record class name.
	 * @return Service the static model class
	 */
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}

	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return 'service';
	}

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		// NOTE: you should only define rules for those attributes that
		// will receive user inputs.
		return array(
			array('title, description, user_id,  activ, date_add, date_expire,amount', 'required'),
			array('user_id, category_id, activ', 'numerical', 'integerOnly'=>true),
			array('title, img1, img2, img3, img4, img5', 'length', 'max'=>255),
			array('date_add, date_expire', 'length', 'max'=>10),
			// The following rule is used by search().
			// Please remove those attributes that should not be searched.
			array('id, title, description, user_id, category_id, activ, date_add, date_expire, img1, img2, img3, img4, img5', 'safe', 'on'=>'search'),
		);
	}

	/**
	 * @return array relational rules.
	 */
	public function relations()
	{
		// NOTE: you may need to adjust the relation name and the related
		// class name for the relations automatically generated below.
		return array(
		);
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'id' => 'ID',
			'title' => 'Title',
			'description' => 'Description',
			'user_id' => 'User',
			'category_id' => 'Category',
			'activ' => 'Activ',
			'date_add' => 'Date Add',
			'date_expire' => 'Date Expire',
			'img1' => 'Img1',
			'img2' => 'Img2',
			'img3' => 'Img3',
			'img4' => 'Img4',
			'img5' => 'Img5',
		);
                return array(
            'id' => 'ID',
            'title' => Yii::t('models', 'Titulo'),
            'descripton' => Yii::t('models', 'Descricao'),
            'category_id' => Yii::t('models', 'Categoria'),
            'activ' => Yii::t('models', 'Ativo'),
            'user_id' => Yii::t('models', 'Utilizador'),
            'date_add' => Yii::t('models', 'Adicionado'),
            'date_expire' => Yii::t('models', 'Expira'),
            'amount' => Yii::t('models', 'Preço'),
            'img1' => 'Img1',
            'img2' => 'Img2',
            'img3' => 'Img3',
            'img4' => 'Img4',
            'img5' => 'Img5',
        );
	}

	/**
	 * Retrieves a list of models based on the current search/filter conditions.
	 * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
	 */
	public function search()
	{
		// Warning: Please modify the following code to remove attributes that
		// should not be searched.

		$criteria=new CDbCriteria;

		$criteria->compare('id',$this->id);
		$criteria->compare('title',$this->title,true);
		$criteria->compare('description',$this->description,true);
		$criteria->compare('user_id',$this->user_id);
		$criteria->compare('category_id',$this->category_id);
		//$criteria->compare('activ',1);
		$criteria->compare('date_add',$this->date_add,true);
		$criteria->compare('date_expire',$this->date_expire,true);
		$criteria->compare('img1',$this->img1,true);
		$criteria->compare('img2',$this->img2,true);
		$criteria->compare('img3',$this->img3,true);
		$criteria->compare('img4',$this->img4,true);
		$criteria->compare('img5',$this->img5,true);

		return new CActiveDataProvider($this, array(
			'criteria'=>$criteria,
		));
	}
        
        public function searchFrontEnd() {
        // Warning: Please modify the following code to remove attributes that
        // should not be searched.

        $criteria = new CDbCriteria;

        $criteria->compare('activ', 1);
  
        return new CActiveDataProvider($this, array(
            'criteria' => $criteria,
        ));
    }
}